package com.eascs.p2p.admin.service.impl;

import javax.inject.Inject;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.app.dao.PageResult;
import com.eascs.p2p.admin.manager.IMsgTemplateManager;
import com.eascs.p2p.common.entity.MsgTemplateEntity;
import com.eascs.p2p.common.service.IMsgTemplateService;
import com.eascs.p2p.common.vo.ModelResult;
import com.eascs.p2p.common.vo.MsgTemplateQueryVO;

@Service
public class MsgTemplateServiceImpl implements IMsgTemplateService {
	@Inject
	IMsgTemplateManager msgTemplateManager;

	@Override
	public ModelResult<Boolean> add(MsgTemplateEntity entity) {

		ModelResult<Boolean> result = new ModelResult<Boolean>();
		try {
			result.setModel(msgTemplateManager.add(entity));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("添加模板：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<Boolean> update(MsgTemplateEntity entity) {

		ModelResult<Boolean> result = new ModelResult<Boolean>();
		try {
			result.setModel(msgTemplateManager.update(entity));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("更新模板：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<MsgTemplateEntity> queryById(String id) {

		ModelResult<MsgTemplateEntity> result = new ModelResult<MsgTemplateEntity>();
		try {
			result.setModel(msgTemplateManager.queryById(id));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("根据ID查询模板：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<MsgTemplateEntity> queryByCode(String code) {

		ModelResult<MsgTemplateEntity> result = new ModelResult<MsgTemplateEntity>();
		try {
			result.setModel(msgTemplateManager.queryByCode(code));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("根据code查询模板：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<Boolean> lock(String id, boolean lock) {

		ModelResult<Boolean> result = new ModelResult<Boolean>();
		try {
			result.setModel(msgTemplateManager.lock(id, lock));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("模板的开启与关闭：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<PageResult<Object[]>> page(MsgTemplateQueryVO vo) {

		ModelResult<PageResult<Object[]>> result = new ModelResult<PageResult<Object[]>>();
		try {
			result.setModel(msgTemplateManager.page(vo));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("模板分页查询：", e.getMessage());
		}
		return result;
	}

}
